package com.andeveloper.springdemo.service.wrapper.impl;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.andeveloper.springdemo.dao.ProductDao;
import com.andeveloper.springdemo.model.Product;
import com.andeveloper.springdemo.service.wrapper.product.ProductDaoWrapper;
import com.google.code.ssm.api.InvalidateSingleCache;
import com.google.code.ssm.api.ParameterValueKeyProvider;
import com.google.code.ssm.api.ReadThroughSingleCache;

@Service
public class ProductDaoWrapperImpl implements ProductDaoWrapper {

	private static final String NAMESPACE = "Product";
	private static Logger logger = Logger.getLogger(ProductDaoWrapperImpl.class);

	@Resource
	private ProductDao productDao;
	
	@Override
	@ReadThroughSingleCache(namespace=NAMESPACE, expiration=3600)
	public Product getProductById(@ParameterValueKeyProvider Integer id) {
		logger.info("read product from db");
		return productDao.getProductById(id);
	}

	@Override
	@InvalidateSingleCache(namespace=NAMESPACE)
	public Integer updateProduct(@ParameterValueKeyProvider Product product) {
		logger.info("update product set to db");
		return productDao.updateProduct(product);
	}

}
